/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jtmcraft.game;

import java.util.ArrayList;
import java.util.List;
import jtmcraft.game.units.GameUnit;

/**
 *
 * @author tom
 */
public class Player {

    private int resources = 100;

    private ArrayList<GameUnit> gameUnits = new ArrayList<GameUnit>();
    private ArrayList<GameUnit> mobileUnits = new ArrayList<GameUnit>();
    private ArrayList<GameUnit> buildingUnits = new ArrayList<GameUnit>();
    private GameUnit storehouse;

    public Player() {
    }
    
    
    public void addMobileUnit( GameUnit gameUnit )
    {
        mobileUnits.add(gameUnit);
        gameUnits.add(gameUnit);
    }

    public List< GameUnit > getMobileUnitList()
    {
       return  mobileUnits;
    }

    public void addBuildingUnit( GameUnit buildingUnit )
    {
        buildingUnits.add(buildingUnit);
        gameUnits.add(buildingUnit);
    }

    public List<GameUnit> getBuildingUnitList()
    {
       return buildingUnits;
    }

    public List<GameUnit> getGameUnits() {
        return gameUnits;
    }

    public void addResources( int amount ) {
        resources += amount;
    }

    public void takeResources( int amount ) {
        if( amount > resources ) {
            throw new IllegalStateException("Not enough resources");
        }
        resources -= amount;
    }

    public GameUnit getStorehouse() {
        return storehouse;
    }

    public void setStorehouse(GameUnit storehouse) {
        this.storehouse = storehouse;
        addBuildingUnit( storehouse );
    }

    public boolean removeUnit( GameUnit unit )
    {
        if( gameUnits.remove(unit) ) {
            mobileUnits.remove(unit);
            buildingUnits.remove(unit);
            return true;
        }
        return false;
    }
   
}